package mya.mes.mdc.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import mya.mes.mdc.model.alarm.MdcAlarm;

import java.io.IOException;

public class MdcAlarmJson extends JsonSerializer<MdcAlarm> {
    @Override
    public void serialize(MdcAlarm value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeStartObject();

        out(gen, "objectId", value.getObjectId());

        out(gen, "alarmTypeId", value.getAlarmTypeId());
        out(gen, "mdcTag", value.getMdcTag());
        out(gen, "bitIndex", value.getBitIndex());
        out(gen, "zoneId", value.getZoneId());


        out(gen, "alarmNo", value.getAlarmNo());
        out(gen, "systemAlarm", value.getSystemAlarm());
        out(gen, "alarmDate", value.getAlarmDate());
        out(gen, "alarmTime", value.getAlarmTime());

        out(gen, "alarmDTime", value.getAlarmDTime());
        out(gen, "alarmSeq", value.getAlarmSeq());


        out(gen, "closeDate", value.getCloseDate());
        out(gen, "closeTime", value.getCloseTime());
        out(gen, "closeDTime", value.getCloseDTime());

        out(gen, "shop", value.getShop());
        out(gen, "area", value.getArea());
        out(gen, "section", value.getSection());
        out(gen, "point", value.getPoint());


        out(gen, "maint", value.getMaint());
        out(gen, "isClosed", value.getClosed());
        out(gen, "timeSpan", value.getTimeSpan());
        out(gen, "timeSpanSec", value.getTimeSpanSec());


        out(gen, "zhCN", value.getZhCN());
        out(gen, "enUs", value.getEnUs());
        out(gen, "msgNotice", value.getMsgNotice());
        out(gen, "timestamp", value.getTimestamp());


        out(gen, "timeWaitToPerson", value.getTimeWaitToPerson());
        out(gen, "timeWaitToManager", value.getTimeWaitToManager());
        out(gen, "hasSentToPerson", value.getHasSentToPerson());
        out(gen, "hasSentToManager", value.getHasSentToManager());

        out(gen, "wxPersonTag", value.getWxPersonTag());
        out(gen, "wxManagerTag", value.getWxManagerTag());


        gen.writeEndObject();
    }


    private void out(JsonGenerator gen, String field, String value) throws IOException {
        if (value == null) {
            return;
        }

        gen.writeStringField(field, value);
    }

    private void out(JsonGenerator gen, String field, Integer value) throws IOException {
        if (value == null) {
            return;
        }

        gen.writeNumberField(field, value);
    }


    private void out(JsonGenerator gen, String field, Long value) throws IOException {
        if (value == null) {
            return;
        }

        gen.writeNumberField(field, value);
    }

    private void out(JsonGenerator gen, String field, Boolean value) throws IOException {
        if (value == null) {
            return;
        }

        gen.writeBooleanField(field, value);
    }
}
